package com.webinsky.article.persist.dao;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ArticleRelateMapperProvider {
	
	private static final String SELECT_TEMP = "select id, article_id, relate_article_id, sort, del, create_at, update_at, language from article_relate";
	
	@SuppressWarnings("unchecked")
	public String selectByArticleIds(Map<String, Object> params) {
		List<Integer> ids = (List<Integer>)params.get("articleIds");
		String condition = "";
		if ( ids != null && !ids.isEmpty() ) {
			List<String> strIds = ids.stream().map(e -> String.valueOf(e)).collect(Collectors.toList());
			condition = " and article_id in (" + String.join(",", strIds) + ")";
		}
		return SELECT_TEMP + " where del = 0" + condition;
	}
}
